<?php

class Room_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function listRateType() {
		$this->db->select('*');
		$this->db->from('room_rate');
		$this->db->join('room_type', 'room_type.room_type_id=room_rate.room_type_id', 'left');
		$this->db->join('rate_type', 'rate_type.rate_type_id=room_rate.rate_type_id', 'left');

        return $this->db->get();
    }
	
	function room_type() {
		$this->db->select('*');
		$this->db->from('room_type');
		
		return $this->db->get();
	}
	
	function rate_type() {
		$this->db->select('*');
		$this->db->from('rate_type');
		$this->db->where('deleted','No');
		
		return $this->db->get();
	}

    function listRateAjax($rate_type_id, $room_type_id) {
        $this->db->select('*');
		$this->db->from('room_rate');
		$this->db->join('room_type', 'room_type.room_type_id=room_rate.room_type_id', 'left');
		$this->db->join('rate_type', 'rate_type.rate_type_id=room_rate.rate_type_id', 'left');
		if($rate_type_id != 0) $this->db->where('room_rate.rate_type_id', $rate_type_id);
		if($room_type_id != 0) $this->db->where('room_rate.room_type_id', $room_type_id);

        return $this->db->get();
    }

    function addRateAjax($data) {
       $this->db->insert('room_rate', $data);
	   return $this->db->insert_id();
    }

    function editRateAjax($id, $data) {
		$this->db->where('room_rate_id', $id);
		$this->db->update('room_rate', $data);        
    }

    function delRateAjax($id) {
        $sql = "DELETE FROM `room_rate` where room_rate_id = " . $id;
        $this->db->query($sql);
    }
	
	function get_material($material_id) {
		$this->db->select();
		$this->db->from('material');
		$this->db->where('material_id', $material_id);
		
		return $this->db->get();
	}
	
	function cleaning($id){
		$this->db->where('room_id', $id);
		$this->db->set('room_status', 'Cleaning');
		$this->db->update('room');
	}
	
	function dirty($id){
		$this->db->where('room_id', $id);
		$this->db->set('room_status', 'Dirty');
		$this->db->update('room');
	}
	
	function ready($id){
		$this->db->where('room_id', $id);
		$this->db->set('room_status', 'Ready');
		$this->db->update('room');
	}

}